package com.company.model;

import com.company.model.request.CompanyForm;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * 公司实体 Created by tu on 2017/1/1.
 */
@Entity
@Table(name = "companies")
public class Company implements Serializable {

  private static final long serialVersionUID = 5970872531189818010L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private Long id;

  @Column(name = "name")
  private String name;

  @Column(name = "description")
  private String description;

  @Column(name = "address")
  private String address;
  /**
   * 官网
   */
  @Column(name = "official_website")
  private String url;

  /**
   * 好评数量
   */
  @Column(name = "digg_count")
  private int diggCount;

  /**
   * 差评 数量
   */
  @Column(name = "bury_count")
  private int buryCount;

  /**
   * 评论数量+喜欢数量
   */
  @JsonIgnore
  @Column(name = "hot_count")
  private int hotCount;

  /**
   * 喜欢数量
   */
  @Column(name = "like_count")
  private int likeCount;

  @JsonIgnore
  private int sort;

  @Column(name = "create_time")
  private Date createTime;

  @JsonIgnore
  @Column(name = "update_time")
  private Date updateTime;

  @JsonIgnore
  @Column(name = "create_user")
  private String createUser;

  @JsonIgnore
  @Column(name = "is_delete")
  private int deleted;

  public Company() {
  }

  public Company(CompanyForm info) {
    address = info.getAddress();
    name = info.getName().trim();
    description = info.getDesc();
    createTime = new Date();
    updateTime = createTime;
    if (!Strings.isNullOrEmpty(address)) {
      address = address.trim();
    }

    if (!Strings.isNullOrEmpty(description)) {
      description = description.trim();
    }

    url = info.getUrl();
    if (!Strings.isNullOrEmpty(url)) {
      url = url.trim();
    }
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getDescription() {
    return description;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public int getDiggCount() {
    return diggCount;
  }

  public void setDiggCount(int diggCount) {
    this.diggCount = diggCount;
  }

  public int getBuryCount() {
    return buryCount;
  }

  public void setBuryCount(int buryCount) {
    this.buryCount = buryCount;
  }

  public int getHotCount() {
    return hotCount;
  }

  public void setHotCount(int hotCount) {
    this.hotCount = hotCount;
  }

  public int getSort() {
    return sort;
  }

  public void setSort(int sort) {
    this.sort = sort;
  }

  public Date getCreateTime() {
    return createTime;
  }

  public void setCreateTime(Date createTime) {
    this.createTime = createTime;
  }

  public Date getUpdateTime() {
    return updateTime;
  }

  public void setUpdateTime(Date updateTime) {
    this.updateTime = updateTime;
  }

  public String getCreateUser() {
    return createUser;
  }

  public void setCreateUser(String createUser) {
    this.createUser = createUser;
  }

  public int getDeleted() {
    return deleted;
  }

  public void setDeleted(int deleted) {
    this.deleted = deleted;
  }

  public int getLikeCount() {
    return likeCount;
  }

  public void setLikeCount(int likeCount) {
    this.likeCount = likeCount;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Company company = (Company) o;

    if (diggCount != company.diggCount) {
      return false;
    }
    if (buryCount != company.buryCount) {
      return false;
    }
    if (hotCount != company.hotCount) {
      return false;
    }
    if (likeCount != company.likeCount) {
      return false;
    }
    if (sort != company.sort) {
      return false;
    }
    if (deleted != company.deleted) {
      return false;
    }
    if (id != null ? !id.equals(company.id) : company.id != null) {
      return false;
    }
    if (name != null ? !name.equals(company.name) : company.name != null) {
      return false;
    }
    if (description != null ? !description.equals(company.description)
        : company.description != null) {
      return false;
    }
    if (address != null ? !address.equals(company.address) : company.address != null) {
      return false;
    }
    if (url != null ? !url.equals(company.url) : company.url != null) {
      return false;
    }
    if (createTime != null ? !createTime.equals(company.createTime) : company.createTime != null) {
      return false;
    }
    if (updateTime != null ? !updateTime.equals(company.updateTime) : company.updateTime != null) {
      return false;
    }
    return createUser != null ? createUser.equals(company.createUser) : company.createUser == null;
  }

  @Override
  public int hashCode() {
    int result = id != null ? id.hashCode() : 0;
    result = 31 * result + (name != null ? name.hashCode() : 0);
    result = 31 * result + (description != null ? description.hashCode() : 0);
    result = 31 * result + (address != null ? address.hashCode() : 0);
    result = 31 * result + (url != null ? url.hashCode() : 0);
    result = 31 * result + diggCount;
    result = 31 * result + buryCount;
    result = 31 * result + hotCount;
    result = 31 * result + likeCount;
    result = 31 * result + sort;
    result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
    result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
    result = 31 * result + (createUser != null ? createUser.hashCode() : 0);
    result = 31 * result + deleted;
    return result;
  }

  @Override
  public String toString() {
    return "Company{" +
        "id=" + id +
        ", name='" + name + '\'' +
        ", description='" + description + '\'' +
        ", address='" + address + '\'' +
        ", url='" + url + '\'' +
        ", diggCount=" + diggCount +
        ", buryCount=" + buryCount +
        ", hotCount=" + hotCount +
        ", likeCount=" + likeCount +
        ", sort=" + sort +
        ", createTime=" + createTime +
        ", updateTime=" + updateTime +
        ", createUser='" + createUser + '\'' +
        ", deleted=" + deleted +
        '}';
  }
}